/*
    This source file is part of GeNa project.
    Copyright © GeNa project 2008
    For the latest info, see http://code.google.com/p/genaproject/ or  http://lumpyproject.forums-rpg.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef BUFFEROBJECT_H_INCLUDED
#define BUFFEROBJECT_H_INCLUDED

#include <GL/glew.h>

class BufferObject
{
private:
    unsigned int m_size;
    unsigned int m_id;

    GLenum m_target;
    GLenum m_usage;

public:
    BufferObject(GLenum target, unsigned int size, GLenum usage)
    {
        m_usage = usage;
        m_target = target;
        m_size = size;

        glGenBuffers(1, &m_id);
        glBindBuffer(m_target, m_id);
        glBufferData(m_target, m_size, NULL, m_usage);
    }

    void bind()
    {
        glBindBuffer(m_target, m_id);
    }

    unsigned int getSize()
    {
        return m_size;
    }

    unsigned int getId()
    {
        return m_id;
    }

    void* map(GLenum access)
    {
        glBindBuffer(m_target, m_id);
        return glMapBuffer(m_target, access);
    }

    void unMap()
    {
        glBindBuffer(m_target, m_id);
        glUnmapBuffer(m_target);
    }
};

#endif // BUFFEROBJECT_H_INCLUDED
